<?php

define("DATABASE_VERSION", "1.00");
define("DATABASE_INT_VERSION", 100);

define("DATABASE_EDITION", "forum");

// table definitions are in database_setup.php

// functions
function database_connect($db_host, $db_user, $db_pass, $db_name) {
	$db_connect = @mysql_connect($db_host, $db_user, $db_pass);
	$db_select = @mysql_select_db($db_name);
	if (!$db_connect) {
		die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>Nie mozna bylo nawiazac polacznia z baza danych!</b><br />".mysql_errno()." : ".mysql_error()."</div>");
	} elseif (!$db_select) {
		die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>Nie mozna wbylo wybrac bazy danych!</b><br />".mysql_errno()." : ".mysql_error()."</div>");
	}
}

function database_query($query){ 
	$result = @mysql_query($query);
	if (!$result) {
		echo mysql_error();
		return false;
	} else {
		return $result;
	}
}

function database_query_without_error($query){ 
	$result = @mysql_query($query);
	if (!$result) {
		return false;
	} else {
		return true;
	}
}

function database_array($query){
	$result = @mysql_fetch_assoc($query);
	if (!$result) {
		echo mysql_error();
		return false;
	} else {
		return $result;
	}
}

function database_rows($query) {
	$result = @mysql_num_rows($query);
	return $result;
}

function database_count($field, $table, $conditions = "") {
	$cond = ($conditions ? " WHERE ".$conditions : "");
	$result = @mysql_query("SELECT Count".$field." FROM ".$table.$cond);
	if (!$result) {
		echo mysql_error();
		return false;
	} else {
		$rows = mysql_result($result, 0);
		return $rows;
	}
}

function database_end(){
	mysql_close();
	return true;
}

require_once SITE."database_setup.php";

// settings functions
require_once INCLUDES_FOLDER."functions-settings.php";

// users functions
require_once INCLUDES_FOLDER."functions-users.php";

?>

